<!--
    说明：招聘企业-企业预览pc
 -->
<template>
  <section class="pc-review-page">
    <!-- 公司基本信息 -->
    <div class="company-info">
      <img
        v-if="companyInfo.companyLogo"
        v-imgError
        class="logo-img"
        :src="companyInfo.companyLogo"
        alt="logo-img"
      >
      <img
        v-else
        v-imgError
        class="logo-img"
        src="../../../assets/images/logo_demo.png"
        alt="logo-img"
      >
      <div class="right-block">
        <div class="name">{{ companyInfo.companyName }}</div>
        <div v-if="companyInfo.industry" class="area">{{ companyInfo.industry[companyInfo.industry.length - 1] }}</div>
      </div>
      <div class="right-hire">
        <div class="hire-num">{{ companyInfo.recruitmentCount || 0 }}</div>
        <div class="hire-title">在招职位</div>
        <div class="click-num">点击量：{{ companyInfo.clickCount || 0 }}</div>
      </div>
    </div>
    <!-- 热招职位 -->
    <div class="row-item">
      <div class="title">
        热招职位
        <div class="all">查看全部职位<span class="all-icon" /></div>
      </div>
      <div id="jobSwiper" class="swiper">
        <div class="swiper-wrapper">
          <div class="swiper-slide">
            <div class="job-item">
              <div class="job-name">
                预览职位1 <span class="salary">200-250/天</span>
              </div>
              <div class="other">
                4天/周 <span class="line" /> 3个月<span class="line" />本科<span class="line" />在校<span class="line" />深圳
              </div>
            </div>
          </div>
          <div class="swiper-slide">
            <div class="job-item">
              <div class="job-name">
                预览职位2 <span class="salary">200-250/天</span>
              </div>
              <div class="other">
                4天/周 <span class="line" /> 3个月<span class="line" />本科<span class="line" />在校<span class="line" />深圳
              </div>
            </div>
          </div>
          <div class="swiper-slide">
            <div class="job-item">
              <div class="job-name">
                预览职位3 <span class="salary">200-250/天</span>
              </div>
              <div class="other">
                4天/周 <span class="line" /> 3个月<span class="line" />本科<span class="line" />在校<span class="line" />深圳
              </div>
            </div>
          </div>
          <div class="swiper-slide">
            <div class="job-item">
              <div class="job-name">
                预览职位4 <span class="salary">200-250/天</span>
              </div>
              <div class="other">
                4天/周 <span class="line" /> 3个月<span class="line" />本科<span class="line" />在校<span class="line" />深圳
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 企业简介 -->
    <div class="row-item">
      <div class="title">{{ companyInfo.companyName }}简介</div>
      <div
        v-if="companyInfo.introduction"
        class="company-desc"
        v-html="companyInfo.introduction.replace(/\n/gm, '<br>')"
      />
      <el-empty v-else description="暂无数据" />
    </div>
    <!-- 企业环境 -->
    <div class="row-item">
      <div class="title">企业环境</div>
      <div
        v-if="Array.isArray(imgVideoList) && imgVideoList.length"
        id="myWebSwiper"
        class="company-environment swiper"
      >
        <div class="swiper-wrapper">
          <div
            v-for="(item, index) in imgVideoList"
            :key="index"
            class="swiper-slide"
          >
            <div style="height: 155px">
              <el-image
                v-if="item.type == 'img'"
                :src="item.url"
                alt=""
                :preview-src-list="imgList.src"
                fit="cover"
                style="width: 250px;height: 135px"
              />
              <div v-else style="width: 100%;height: 135px">
                <vueVideoPlayer
                  :ref="`video${index}`"
                  :autoplay="false"
                  :src="item.url"
                  @onPlay="videoPlay(index)"
                />
              </div>
              <div
                v-if="item.updateTime"
                style="text-align: right; font-size: 12px; color: #9597a0; margin-bottom: 20px;"
              >
                更新时间：{{ item.updateTime }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 企业地址 -->
    <div class="row-item">
      <div class="title">企业地址</div>
      <div
        v-if="
          companyInfo.companyAddress &&
            companyInfo.companyAddress.length > 0
        "
        class="company-address"
      >
        <div
          v-for="(item, index) in companyInfo.companyAddress"
          :key="index"
          class="item"
        >
          <span class="position-icon" />
          {{ item.province !== item.city ? item.province : '' }}
          {{ item.city }}
          {{ item.address }}
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/swiper.scss'
import vueVideoPlayer from '../../../components/videoPlayer'

import {
  getEducationName
} from '@/utils/frontDataDict.js'
export default {
  name: 'PcReview',
  components: {
    vueVideoPlayer
  },
  data() {
    return {
      tagType: 0,
      swiper: null,
      jobSwiper: null,
      companyInfo: {},
      imgList: [],
      imgVideoList: []
    }
  },
  mounted() {
  },
  methods: {
    init(companyInfo) {
      const data = JSON.parse(JSON.stringify(companyInfo))
      if (data) {
        try {
          if (Array.isArray(JSON.parse(data.industry))) {
            data.industry = JSON.parse(data.industry)[1]
          }
          if (Array.isArray(JSON.parse(data.companyAddress))) {
            data.companyAddress = JSON.parse(data.companyAddress)
          }
          data.education = getEducationName(data.education)
        } catch {
          () => {}
        }
        try {
          this.imgVideoList = []
          data.environment = JSON.parse(data.environment)
          data.environment.videoList.forEach((v) => {
            v.src && this.imgVideoList.push({
              type: 'video',
              url: v?.src ?? v,
              updateTime: v?.updateTime ?? ''
            })
          })
          data.environment.imgList.forEach((v) => {
            this.imgVideoList.push({
              type: 'img',
              url: v?.src ?? v,
              updateTime: v?.updateTime ?? ''
            })
          })
        } catch {
          () => {}
        }
        this.companyInfo = data
        this.imgList = data.environment.imgList
        setTimeout(() => {
          this.initSwiper()
        })
      }
    },
    stopVideo() {
      this.imgVideoList.map((item, inx) => {
        if (item.type === 'video') {
          this.$refs[`video${inx}`][0].pause()
        }
      })
    },
    videoPlay(index) {
      const videoItem = this.$refs[`video${index}`][0]
      videoItem &&
        this.imgVideoList.map((item, inx) => {
          if (item.type === 'video' && inx !== index) {
            this.$refs[`video${inx}`][0].pause()
          }
        })
    },
    initSwiper() {
      if (this.swiper === null) {
        this.swiper = new Swiper('#myWebSwiper', {
          slidesPerView: 'auto',
          spaceBetween: 10,
          observer: true,
          observeParents: true
        })
      }
      if (this.jobSwiper === null) {
        this.jobSwiper = new Swiper('#jobSwiper', {
          slidesPerView: 'auto',
          spaceBetween: 10,
          observer: true,
          observeParents: true
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.pc-review-page {
  position: relative;
  padding: 15px 10px;
  width: 375px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #d4d6da;
  overflow: hidden;
  .company-info {
    position: relative;
    height: 92px;
    width: 100%;
    border-bottom: 1px solid #d4d6da;
    .logo-img {
      display: block;
      width: 63px;
      height: 63px;
      background: #ffffff;
      border-radius: 6px;
      border: 1px solid #d4d6da;
      float: left;
      margin-right: 12px;
    }
    .right-block {
      position: relative;
      overflow: hidden;
      width: calc(100% - 75px);
      height: 63px;
      display: flex;
      flex-flow: column nowrap;
      justify-content: center;
      align-items: flex-start;
      .name {
        font-size: 16px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #37383d;
        line-height: 30px;
        margin-bottom: 5px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        width: 250px;
      }
      .area {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 21px;
      }
    }
    .right-hire {
      position: absolute;
      top: 0;
      right: 0;
      height: 100%;
      display: flex;
      flex-flow: column nowrap;
      justify-content: flex-start;
      align-items: flex-end;
      .hire-num {
        font-size: 20px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #37383d;
        line-height: 28px;
        margin-bottom: 2px;
        padding-right: 7px;
      }
      .hire-title {
        font-size: 12px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 17px;
        margin-bottom: 2px;
      }
      .click-num {
        font-size: 10px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 14px;
      }
    }
  }
  #jobSwiper {
    position: relative;
    width: 365px;
    margin-left: -10px;
    .swiper-slide {
      width: 322px;
    }
  }
  #myWebSwiper {
    width: 365px;
    margin-left: -10px;
  }
  .row-item {
    position: relative;
    width: 100%;
    padding: 10px;
    border-bottom: 1px solid #d4d6da;
    &:last-child {
      border-bottom: 1px solid #fff;
    }
    .title {
      position: relative;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      text-align: left;
      font-weight: 500;
      color: #37383d;
      line-height: 22px;
      margin-bottom: 15px;
      .all {
        position: absolute;
        right: 0;
        bottom: 0;
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #9597a0;
        line-height: 17px;
        vertical-align: bottom;
        cursor: pointer;
        .all-icon {
          display: inline-block;
          width: 9px;
          height: 18px;
          background: url("../../../assets/images/more.png") no-repeat center
            center / cover;
          vertical-align: bottom;
          margin-left: 3px;
        }
      }
    }
    .job-item {
      position: relative;
      width: 325px;
      background: #ffffff;
      border-radius: 6px;
      border: 1px solid #d4d6da;
      padding: 15px;
      cursor: pointer;
      .job-name {
        font-size: 17px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #37383d;
        line-height: 24px;
        margin-bottom: 23px;
        .salary {
          font-size: 15px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #9597a0;
          line-height: 12px;
          float: right;
        }
      }
      .other {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #9597a0;
        line-height: 19px;
        .line {
          position: relative;
          display: inline-block;
          width: 1px;
          height: 9px;
          background: #9597a0;
          margin: 0 11px;
        }
      }
    }
    .company-desc {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #9597a0;
      line-height: 25px;
    }
    .swiper {
      width: 100%;
      height: 100%;
    }
    .company-environment {
      .swiper-slide {
        text-align: left;
        font-size: 18px;
        background: #fff;
        /* Center slide text vertically */
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
      }
      .swiper-slide img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
    }
    .company-address {
      position: relative;
      .item {
        position: relative;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #37383d;
        line-height: 20px;
        background: #f9f9f9;
        border-radius: 2px;
        border: 1px solid #f0f0f0;
        cursor: pointer;
        margin-top: 10px;
        padding: 8px 10px 8px 35px;
        &:first-child {
          margin-top: 0;
        }
        .position-icon {
          position: absolute;
          left: 13px;
          top: 50%;
          transform: translateY(-50%);
          display: inline-block;
          width: 12px;
          height: 14px;
          background: url("../../../assets/images/position.png") no-repeat
            center center / cover;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>
